<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'newBrand.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  	<script>
  				function newbrand(){
  					var newName=$("#newbrand").val();
  					$.post("InsertBrandAction",{"brandName":newName},function(data){
  							if(data=="success"){
  								alert("增加成功");
  								$("#newbrand").val("");
  							}else{
  								alert("增加失败");
  								$("#newbrand").val("");
  							}
  					});
  				}
  				function checkBrandName(){
  					var newName=$("#newbrand").val();
  					$.post("checkBrandNameAction",{"brandName":newName},function(data){
  							if(data=="yes"){
  								alert("这个品牌已经存在");
  								$("#newbrand").val("");
  								return null;
  							}else{
  								newbrand();
  							}
  					});
  				}
  	
  	</script>
  </head>
  
  <body>
   			<div align="center">
   					<h3>增加新的品牌</h3>
   					<label>新的名字:</label>
   					<input type="text" name="newbrand" id="newbrand">
   					<input type="button" onclick="checkBrandName()" value="添加">
   			</div>
  </body>
</html>
